" =============== plugin: 插件管理 ===============
" ======= 预设制:
let $THEME="molokai"
" --- code编码:
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
" ======= 路径配置:
if(has("win32") || has("win64") || has("win95") || has("win16"))
    " --- windows路径配置
    let $PLAT="windows"
    source $VIMRUNTIME/vimrc_example.vim
    " 载入windows系统的快捷键
    source $VIMRUNTIME/mswin.vim
    behave mswin
    let langmenu="en_US""
    let $LANG="en_US"
    " 菜单中文
    source $VIM/vim80/delmenu.vim
    source $VIM/vim80/menu.vim
    language messages zh_CN.utf-8
else
    " --- linux路径配置
    let $PLAT="linux"
endif
call plug#begin()

" ======= 插件配置:
Plug 'vim-airline/vim-airline'      " 标题栏
Plug 'scrooloose/nerdtree'    " 导航菜单
Plug 'Xuyuanp/nerdtree-git-plugin'       " 导航栏git显示
Plug 'preservim/nerdcommenter'   " 注解
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'  " 导航栏高亮
Plug 'tmhedberg/SimpylFold'    "  折叠代码
Plug 'vim-scripts/indentpython.vim'   " python自动缩进
Plug 'styled-components/vim-styled-components'
Plug 'crusoexia/vim-monokai'    " vim的sublime类似风格皮肤
Plug 'vim-scripts/taglist.vim'  " 显示函数列表
Plug 'jiangmiao/auto-pairs'     " 自动补全括号
Plug 'MaxMEllon/vim-jsx-pretty'
Plug 'jparise/vim-graphql'
Plug 'scrooloose/syntastic'
Plug 'nvie/vim-flake8'              " pep8检测
Plug 'tpope/vim-fugitive'
Plug 'chxuan/vim-buffer'   " vim的buffer操作
Plug 'vim-airline/vim-airline-themes'   " 标题栏主题
Plug 'wesleyche/SrcExpl'   " 自动跳转
" 语法:
Plug 'pangloss/vim-javascript'       " javascript支持
Plug 'jelera/vim-javascript-syntax'  " javascript 语法高亮
Plug 'godlygeek/tabular'  " markdown
Plug 'plasticboy/vim-markdown' " markdown语法支持
Plug 'luisbarrancos/osl-syntax'  " osl支持
Plug 'http://gitee.com/qiuchangjie/ShaderHighLight.git'   " 针对glsl等shader的语法
" Custom Plugin
Plug 'https://gitee.com/www998www/python-hightlight-syntax.git'    " 自定义高亮
" 平台:
if($PLAT=="linux")
    Plug 'edkolev/tmuxline.vim'
    Plug 'Valloric/YouCompleteMe'  " 代码补全
    Plug 'yggdroot/leaderf'             " 老板f搜索
endif

call plug#end()

" =============== Plugin settings:  插件设置 ===============
let NERDTreeIgnore=['\.pyc$', '\~$']   " 导航栏不显示pyc
let g:SimpylFold_docstring_preview=1     " 折叠代码时显示详细信息
let g:SimpylFold_fold_import=0           " 一开始不折叠代码
set foldmethod=indent                   "  缩进
set foldlevel=99
set laststatus=2
let python_highlight_all=1             " 开启python高亮

" airline标题栏设置
set laststatus=2  " 永远显示状态栏
let g:airline_powerline_fonts = 1
let g:airline_theme=$THEME " 皮肤 
let g:airline#extensions#tabline#enabled=1  " 开启tabline(顶栏)
let g:airline#extensions#tabline#formatter='jsformatter' " 显示标签的样式只显示文件名
let g:airline#extensions#tabline#buffer_nr_show=1
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif

" nerdtree
let g:NERDTreeFileExtensionHighlightFullName = 1
let g:NERDTreeExactMatchHighlightFullName = 1
let g:NERDTreePatternMatchHighlightFullName = 1
let g:NERDTreeHighlightFolders = 1
let g:NERDTreeHighlightFoldersFullName = 1
let g:NERDTreeWinSize=25
let g:NERDTreeDirArrowExpandable = '►'
let g:NERDTreeDirArrowCollapsible = '▼'
let NERDTreeAutoCenter=1

" nerdtree-git-plugin
let g:NERDTreeIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ 'Ignored'   : '☒',
    \ "Unknown"   : "?"
    \ }

" nerd-commenter
let g:NERDDefaultAlign = 'left'

" vim-flake8
let g:flake8_quickfix_height=7

" YouComleteMe
if($PLAT=="windows")
    let g:gitgutter_git_executable = 'C:\Program Files\Git\bin\git.exe'
else
    let g:gitgutter_git_executable = '/usr/bin/git'
    let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
    nnoremap <leader>j :YcmCompleter GoToDefinitionElseDeclaration<CR>
    inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"    "回车即选中当前项
    inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"
    inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"
    inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
    inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"
endif

" taglist:
let Tlist_Show_One_File=1    "只显示当前文件的tags
let Tlist_WinWidth=40        "设置taglist宽度
let Tlist_Exit_OnlyWindow=1  "tagList窗口是最后一个窗口，则退出Vim
let Tlist_Use_Right_Window=1 "在Vim窗口右侧显示taglist窗口


""""""""""""""""""""""""""""""
  "Leaderf settings
""""""""""""""""""""""""""""""
if($PLAT=="linux")
    "文件搜索
    nnoremap <silent> <Leader>f :Leaderf file<CR>
    "历史打开过的文件
    nnoremap <silent> <Leader>h :Leaderf mru<CR>
    "Buffer
    nnoremap <silent> <Leader>b :Leaderf buffer<CR>
    "函数搜索（仅当前文件里）
    nnoremap <silent> <Leader>F :Leaderf function<CR>
    "模糊搜索，很强大的功能，迅速秒搜
    nnoremap <silent> <Leader>r :Leaderf rg<CR>
endif

" =============== Normal settings:  常规设置 ===============
filetype on      "  自动判断文件类型
filetype indent on   " 自动缩进
syntax on             " 自动载入语法
set mouse=a       "  支持鼠标
set encoding=utf-8       "  显示的编码
set hls               " 高亮显示搜索的内容
set number             " 显示行号
set ignorecase          " 搜索无视大小写
set nobackup
set noswapfile           "  不自动产生swap文件
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set smarttab
set smartindent
set noundofile       "  不自动产生undo文件
set selectmode-=mouse,key   " 支持鼠标
set backspace=indent,eol,start   " 支持backspace键
set splitright
set splitbelow


" =============== Theme settings:  主题设置 ===============
set background=dark
if has('gui_running')
    " ======= GUI模式
    if($PLAT=="windows")
        set guifont=Consolas-with-Yahei:h16
    else
        " set guifont=CousineforPowerline\ 17
        set guifont=Ubuntu\ Mono\ for\ powerline\ 17
    endif
    colorscheme monokai
    set background=dark
    let g:monokai_term_italic = 1
    let g:monokai_gui_italic = 1
    set guioptions-=m
    set guioptions-=T
    set guioptions-=r
    set guioptions-=l
    set guioptions-=b
else
    " ======= 命令行模式
    if($PLAT=="windows")
        colorscheme monokai
        set background=dark
        set t_Co=256
    endif
endif


if has('nvim')
    colorscheme monokai
    map <Leader>1 :GuiTabline 0<CR>:Guifont Cousine for Powerline:h17<CR>
    set clipboard+=unnamedplus
    set background=dark
    let g:monokai_term_italic = 1
    let g:monokai_gui_italic = 1
    set guioptions-=m
    set guioptions-=T
    set guioptions-=r
    set guioptions-=l
    set guioptions-=b
    set t_Co=256
endif

" =============== Language settings:  语言设置 ===============
" ======= python:
au BufNewFile,BufRead *.py
            \ set syntax=python
au BufNewFile,BufRead *.h
            \ set syntax=cpp
au BufNewFile,BufRead *.cpp
            \ set syntax=cpp
au BufNewFile,BufRead *.osl
            \ set syntax=osl
au BufNewFile,BufRead *.ma
            \ set syntax=mel

" =============== Map key settings: 快捷键映射 ===============
" ======= 整体映射
" 用系统剪切板复制粘贴
map <C-c> "+y
map <C-x> "+d
map <C-v> "+gp
"  选词搜索
map <C-f> <S-*>v
"  关闭搜索影响(搜索问号)
map <S-f> /?<CR>
"  打开vim配置文本编辑
if($PLAT=="windows")
    map <c-f1> :edit $USERPROFILE\_vimrc<CR>
else
    map <c-f1> :edit ~/.vimrc<CR>
endif
"  打开或关闭导航栏
map <C-N> :NERDTreeToggle<CR>
"  打开taglist看函数列表
map mm :TlistToggle<cr>
" tab翻页
map <C-w> :PreviousBuffer<CR>
map <C-s> :NextBuffer<CR>
" 注释:
map <Leader>cy :NERDCommenterComment
map <Leader>cn :NERDCommenterNested
map <Leader>cc :NERDCommenterToggle
" 自动跳转源码:
nmap se :SrcExplToggle<CR>

" ======= normal模式映射
" 回撤
nnoremap <C-z> u
" 在不同blank(分页栏)之间切换
nnoremap <C-j> <C-W><C-J>
nnoremap <C-k> <C-W><C-K>
nnoremap <C-l> <C-W><C-L>
nnoremap <C-h> <C-W><C-H>
" 折叠代码
nnoremap <space> za
" 全选
nnoremap <C-a> ggVG
" 左右多行缩进
nnoremap <C-=> <S-<><S-<>
nnoremap <C-]> <S->><S->>
" 全选单词
nnoremap ee viw
" 把该行上移动
nnoremap <S-d> ddp
" 把该行下移
nnoremap <S-u> ddkkp
" 全选整行
nnoremap <S-l> ^v$
nnoremap <Leader>3 ^i#


" ======= 编辑模式映射
" 复制粘贴
inoremap <C-z> <ESC>ui
inoremap <C-v> <ESC>"+gpi
" 在编辑模式中移动
inoremap <A-h> <ESC><Left>i
inoremap <A-l> <ESC><Right>a
inoremap <A-j> <ESC><Down>a
inoremap <A-k> <ESC><Up>a
" 删除后面一个字符
inoremap <A-'> <ESC>lxa

" ======= 选择(可视模式)映射
vnoremap <C-[> <S-<>
vnoremap <C-]> <S->>
" 大小写转换:
vnoremap <C-u> gU
vnoremap <C-d> gu

" 检查PEP8
nnoremap <C-\> :call Flake8()<CR>
hi Normal ctermfg=152 ctermbg=none
